//
//  BIZStarView.m
//  biz
//
//  Created by zhangfuwei on 2017/4/14.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZStarView.h"

@implementation BIZStarView {
    NSString    *_imageStr;
    CGRect      _imageRect;
    NSInteger   _imageNum;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithImageStr:(NSString *)image imageRect:(CGRect)rect totalNum:(NSInteger)num {
    self = [super init];
    if (self) {
        _imageStr = image;
        _imageRect = rect;
        _imageNum = num?:1;
        [self loadUI];
    }
    return self;
}

-(void)loadUI {
    
    CGFloat margin = 5;
    for (int i=0; i<_imageNum; i++) {
        
        CGFloat imageX = (margin + _imageRect.size.width)*i;
        CGRect frame = CGRectMake(imageX, 0, _imageRect.size.width, _imageRect.size.height);
        UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_imageStr]];
        imageV.frame = frame;
        [self addSubview:imageV];
    }
}

- (void)setImageNum:(NSInteger)imageNum {
    _imageNum = imageNum;
    [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull subView, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([subView isKindOfClass:[UIImageView class]]) {
            [subView removeFromSuperview];
        }
    }];
    [self loadUI];
}

@end
